#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>

using namespace std;
//brute force
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> sum(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            cin >> sum[i][j];
            if (i > 0)
                sum[i][j] += sum[i - 1][j];
            if (j > 0)
                sum[i][j] += sum[i][j - 1];
            if (i > 0 && j > 0)
                sum[i][j] -= sum[i - 1][j - 1];
        }

    int mini = INT_MAX, maxi = INT_MIN;

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            for(int u = 0;u<=i;u++)
                for(int v=0;v<=j;v++)
                {
                    int ans = sum[i][j];
                    if (u > 0)
                        ans -= sum[u - 1][j];
                    if (v > 0)
                        ans -= sum[i][v - 1];
                    if (u > 0 && v > 0)
                        ans += sum[u - 1][v - 1];
                    maxi = max(ans, maxi);
                }
        }
    cout <<maxi<<endl;
    return 0;
}

//最大子段和
//dp[j] max end with j
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> nums(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> nums[i][j];

    int ans = INT_MIN;
    for (int i = 0; i < n; i++)
    {
        vector<int> sum(n, 0);
        for (int j = i; j < n; j++)
        {
            for (int k = 0; k < n; k++)
                sum[k] += nums[j][k];
            vector<int> dp(n, 0);
            dp[0] = sum[0];
            ans = max(dp[0], ans);
            for (int j = 1; j < n; j++)
            {
                dp[j] = max(dp[j - 1] + sum[j], sum[j]);
                ans = max(dp[j], ans);
            }            
        }
    }
    cout << ans;
}
/*
i-1,j-1 i-1,j
i,j-1   i,j


u,v     u,j
i,v     i,j

[i][j] + [u-1][j] + [i][v-1] - [u-1][v-1]
*/
